﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zocono.WCS.Infrastructure.ApllicationDto.FxModel;

namespace Zocono.WCS.Domain.PlcBytesObject
{
    public class PlanarGeneralPlcActionBOFx : BytesObjectBase
    {
        //public byte PlcTo { get; set; }
        //public byte WcsTo { get; set; }
        //public byte yl_1 { get; set; }
        //public byte yl_2 { get; set; }
        //public byte yl_3 { get; set; }
        public List<DxInfo> Infos { get; set; } = new List<DxInfo>();

        public override void Serialize(long plcConnectionID, long plcReadDbID, int bytesIndex, int bytesLength, int objectIndex, int objectLength, string objectType, string ScEquipmentCode, byte[] bytes)
        {
            PlcConnectionID = plcConnectionID;
            PlcReadDbID = plcReadDbID;
            BytesIndex = bytesIndex;
            BytesLength = bytesLength;
            ObjectIndex = objectIndex;
            ObjectLength = objectLength;
            ObjectType = objectType;

            //PlcTo = HelperByte.GetByteAt(bytes, 0);
            //WcsTo = HelperByte.GetByteAt(bytes, 1);
            //yl_1 = HelperByte.GetByteAt(bytes, 2);
            //yl_2 = HelperByte.GetByteAt(bytes, 3);
            //yl_3 = HelperByte.GetByteAt(bytes, 4);

            //for (int i = 0; i < 25; i++)
            //{
            //    DxInfo dxInfo = new DxInfo();
            //    dxInfo.location = (i + 1);
            //    dxInfo.code = HelperByte.GetCharsAt(bytes, (i * 36 + 0 + bytesIndex), 30);
            //    dxInfo.type = HelperByte.GetIntAt(bytes, (i * 36 + 32+ bytesIndex));
            //    dxInfo.res = HelperByte.GetByteAt(bytes, (i * 36 + 34 + bytesIndex));
            //    Infos.Add(dxInfo);
            //}
            for (int i = 0; i < bytes.Length / 36; i++)
            {
                //0下标没有电芯数据  只有24只电芯
                if (i > 0 && i < 25)
                {
                    DxInfo item = new DxInfo();
                    int lengthItem = HelperByte.GetSIntAt(bytes, 1 + 36 * i);
                    item.code = HelperByte.GetCharsAt(bytes, 2 + 36 * i, lengthItem).Trim();
                    item.type = HelperByte.GetIntAt(bytes, 32 + 36 * i);
                    item.res = HelperByte.GetByteAt(bytes, 34 + 36 * i);
                    item.location = i;
                    Infos.Add(item);
                }
            }

        }

    }
}
